import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}
class Solution {
    List<List<Integer>> ret;
    List<Integer> path;
    public List<List<Integer>> subsetsWithDup(int[] nums) {
        ret = new ArrayList<>();
        path = new ArrayList<>();
        ret.add(new ArrayList<>());
        Arrays.sort(nums);
        dfs(0, nums);
        return ret;
    }
    private void dfs(int pos, int[] nums){
        for(int i = pos; i < nums.length; i++){
            if(i > pos && nums[i] == nums[i - 1]) continue;//树层之间去重
            path.add(nums[i]);
            ret.add(new ArrayList<>(path));//加入结果数组
            dfs(i + 1, nums);
            //回溯 -- 恢复现场
            path.remove(path.size() - 1);
        }
    }
}